package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.common.utils.appkit.FirefightingiotKit;
import com.dataaccess.dataaccess.config.rocketmq.UserProducer;
import com.dataaccess.dataaccess.support.annotaion.Action;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.service.SanJiangYunService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * @Author: YangYu
 * @ClassName: SanJiangYunController
 * @Date: Created in 15:52 2022/10/26
 * @Description: 三江云控制器
 */
@Action
@RequestMapping("sanJiangYun")
public class SanJiangYunController extends BaseController {

    @Resource
    private SanJiangYunService sanJiangYunService;
    @Resource
    private MyLogger logger;
    @Resource
    private UserProducer userProducer;

    /**
     * @Author YangYu
     * @Description  三江云数据变化
     * @Date Created in 17:29 2021/10/27
     * @Param [jsonParam]
     */

    @At(value = "info", method = RequestMethod.POST)
    public RespEntity smokeGateways(@RequestBody(required = false) JSONObject jsonParam) throws Exception  {
        logger.info("sanJiangYun"+"------"+jsonParam);
        jsonParam.put("deviceFlag", "sanJiangYun");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return sanJiangYunService.sanJiangYun(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
}
